<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <input type="text" ref="ipt" />
      <button @click="fn">btn</button>

      <!-- v-for 中的模板引用 -->
      <!-- 获取出来的是一个数组 -->
      <ul>
        <li v-for="item in 5" ref="lis">{{ item }}</li>
      </ul>

      <!-- 函数模板引用 -->
      <div
        :ref="(el) => {
          div = el
        }"
      >
        函数模板引用
      </div>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            div: null,
          };
        },
        // 只有在mounted及以后才能获得dom节点
        mounted() {
          // console.log(document.querySelector("input"));
          // console.log(this.$refs.ipt);
          // this.$refs.ipt.focus();
          console.log(this.$refs.lis);
          console.log(this.div);
        },

        methods: {
          fn() {
            console.log(this.$refs.ipt);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
